<script src="/static/js/jquery-2.1.1.js"></script>
<script src="/static/bootstrap/js/bootstrap.js"></script>
<link href="/static/bootstrap/css/bootstrap.min.css" rel="stylesheet"/>
<link href="/static/layui/css/layui.css" rel="stylesheet"/>
<script src="/static/layui/layui.js"></script>
<link href="/static/css/common.css" rel="stylesheet"/>

<style>
    .config_img{height:45px;margin-top:15px;}
    .layui-form-label{padding:9px 5px;}
    .layui-input-block{margin-left:85px;}
</style>


<div class="modal-body">

    <div class="new-content">
        <form name="add_form" class="form-horizontal layui-form">

            <div class="layui-form-item">
                <label class="layui-form-label wd-140">所属类型</label>
                <div class="layui-input-block ml-110">
                    <select name="type" lay-verify="type" lay-filter="type" >
                        <option value="9" {if condition="$detail['type'] eq 9"} selected {/if}>发布部门</option>
                        <option value="10" {if condition="$detail['type'] eq 10"} selected {/if}>企业规模</option>
                        <option value="11" {if condition="$detail['type'] eq 11"} selected {/if}>行业</option>
                    </select>
                </div>
            </div>


            <div class="layui-form-item">
                <label class="layui-form-label wd-140">名称</label>
                <div class="layui-input-block">
                    <input type="text" class="form-control" name="name" placeholder="名称" value="{$detail.name}">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label wd-140">说明</label>
                <div class="layui-input-block">
                    <input type="text" class="form-control" name="desc" placeholder="说明" value="{$detail.desc}">
                </div>
            </div>


            <div class="layui-form-item js_photos">
                <label class=" layui-form-label"> *缩略图</label>
                <div class="layui-input-block logo">
                    <div class="input-group ">
                        <input type="file" name="" class="do_upload" data-val="image"  style="display: none">
                        <input type="text" class="form-control image" name="image" disabled="" value="{$detail.image}" >
                        <input type="hidden" class="form-control image" name="image" value="{$detail.image}" >
                        <span class="group-span-filestyle input-group-btn" tabindex="0">
                            <label class="btn btn-default id_photos" data-original-title="" title="">
                                <span class="glyphicon glyphicon-folder-open"></span>
                                上传
                            </label>
                        </span>
                        </span>
                    </div>
                    {if condition="$detail['image'] neq ''"}
                    <img class="config_img" src="{$detail.image}" >
                    {/if}
                </div>
            </div>


            <div class="layui-form-item js_photos">
                <label class=" layui-form-label">状态:</label>
                <div class="layui-input-block">
                    <select name="status">
                        <option value="1" {if condition="$detail['status'] eq 1"} selected {/if}>启用</option>
                        <option value="2" {if condition="$detail['status'] eq 2"} selected {/if}>禁用</option>
                    </select>
                </div>
            </div>

            <input type="hidden" name="id" value="{$detail.id}">
        </form>
    </div>

</div>

<script>

    $(".id_photos").click(function () {
        $(this).parent().parent().find(".do_upload").click();
    });

    $('.js_photos').on('change','.do_upload',function(){
        var content = $(this).attr("data-val");
        var formData = new FormData();
        var name = $($(this)).val();
        var files = $($(this))[0].files[0];
        formData.append("file", files);
        formData.append("name", name);
        //另外加的参数
        formData.append("act", "PostImg");
        // var index = layer.msg('正在提交中....');

        $.ajax({
            url: "{:URL('common/upload/ad_upload')}",
            type: 'POST',
            data: formData,
            processData: false,
            contentType: false,
            dataType: 'json',
            success:function (res) {
                $("."+content).val(res.path);
                $("."+content).find("img").attr("src",res.path);
            }
            ,error:function (res) {
                alert('错误');
            }
        });
    })
    layui.use(['form'], function() {
        var form = layui.form
            , layer = layui.layer;
        var layedit = layui.layedit;
        var  tree = layui.tree;
        var util = layui.util;


        layui.form.render('select');
        form.render();
    });
</script>